﻿using LibBinary.DataSource;
using LibBinary.FileData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LibBinary.FileDeclaration.Text
{
    public class ObjectDeclaration : IFileDeclaration
    {
        private readonly IObjectDeclarationProvider provider;

        public ObjectDeclaration(IObjectDeclarationProvider provider)
        {
            this.provider = provider;
        }

        public AbstractFileData Read(TextFileInputSource src, AbstractFileData parentNode)
        {
            src.SkipChar('{');

            if (src.ReadWord() != "object_id")
            {
                throw new ReadingFormatException("Invalid object data.");
            }
            src.SkipChar(':');
            string object_id = src.ReadString();
            src.SkipChar(',');

            var ret = new ObjectData(parentNode);
            ret.ObjectID = object_id;
            ret.Data = provider.Get(object_id).ReadFields(src, ret);

            src.SkipChar('}');
            return ret;
        }

        public void Write(TextFileOutputSource src, AbstractFileData data)
        {
            throw new NotImplementedException();
        }
    }
}
